﻿using System;
using System.IO;


namespace FireBus.Contracts
{
	[Serializable]
	public class ExtensionPath : ValueObject<String>
	{
		public ExtensionPath(String path)
		{
			Value = path ?? String.Empty;
		}

		
		public String GetAbsolutePath()
		{
			var applicationPath = AppDomain.CurrentDomain.BaseDirectory;
			var combinedPath = Path.Combine(applicationPath, Value);
			var absolutePath = Path.GetFullPath(combinedPath);
			return absolutePath;
		}


		public Boolean Exists()
		{
			var absolutePath = GetAbsolutePath();
			return Directory.Exists(absolutePath);
		}


		public static implicit operator String(ExtensionPath path)
		{
			return ToString(path);
		}

		public static String ToString(ExtensionPath path)
		{
			return path == null ? null : path.Value;
		}

		public static implicit operator ExtensionPath(String path)
		{
			return new ExtensionPath(path);
		}
	}
}
